/**
*
* 2007-11-7 下午03:45:06
* @author xuhuan
*/

package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnActionNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnParameter;

public class ActionNodeLoader extends NodeLoader {
	
	public List<Shape> loadNodes(Element root) {
		
		NodeList actionNodes = root.getElementsByTagName(SaturnActionNode.KEY_NODE_ACTION);
		
		List<Shape> shapes = new ArrayList<Shape>(actionNodes.getLength());
		
		for (int i = 0; i < actionNodes.getLength(); ++i) {
			SaturnActionNode saturnActionNode = new SaturnActionNode();
			
			Node actionNode = actionNodes.item(i);
			String shapeId = super.getNodeAttributeValue(actionNode, Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(actionNode, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			
			
			String key = super.getNodeElementValue(actionNode, SaturnActionNode.SHOW_ACTION_NODE_KEY);
			String name = super.getNodeElementValue(actionNode, SaturnActionNode.SHOW_ACTION_NODE_NAME);
			String description = super.getNodeElementValue(actionNode, SaturnActionNode.SHOW_ACTION_NODE_DESCRITPION);
			List<SaturnParameter> parameters = super.getParameters(actionNode);
			
			Point location = super.getLocation(actionNode);
			Dimension size = new Dimension(50, 70);
			
			saturnActionNode.setId(shapeId);
			saturnActionNode.setLocation(location);
			saturnActionNode.setKey(key);
			saturnActionNode.setName(name);
			saturnActionNode.setNextId(nextId);
			saturnActionNode.setDescription(description);
			saturnActionNode.setParameters(parameters);
			saturnActionNode.setSize(size);
			saturnActionNode.setNode(actionNode);
			shapes.add(saturnActionNode);
		}
		
		return shapes;
	}
}
